import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Login.vue')
const Home = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Home.vue')
const Welcome = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Welcome.vue')
// import Login from '../components/Login.vue'
// import Home from '../components/Home.vue'
// import Welcome from '../components/Welcome.vue'

const Users = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/users/Users.vue')
const Rights = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/rights/Rights.vue')
const Roles = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/rights/Roles.vue')
// import Users from '../components/users/Users.vue'
// import Rights from '../components/rights/Rights.vue'
// import Roles from '../components/rights/Roles.vue'

const Categories = () => import(/* webpackChunkName: "categories_params" */ '../components/goolds/Categories.vue')
const Params = () => import(/* webpackChunkName: "categories_params" */ '../components/goolds/Params.vue')
// import Categories from '../components/goolds/Categories.vue'
// import Params from '../components/goolds/Params.vue'

const List = () => import(/* webpackChunkName: "list_add" */ '../components/goolds/List.vue')
const Add = () => import(/* webpackChunkName: "list_add" */ '../components/goolds/Add.vue')
// import List from '../components/goolds/List.vue'
// import Add from '../components/goolds/Add.vue'

const Order = () => import(/* webpackChunkName: "order_report" */ '../components/order')
const Report = () => import(/* webpackChunkName: "order_report" */ '../components/report')
// import Order from '../components/order'
// import Report from '../components/report'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/users', component: Users },
        { path: '/rights', component: Rights },
        { path: '/roles', component: Roles },
        { path: '/categories', component: Categories },
        { path: '/params', component: Params },
        { path: '/goods', component: List },
        { path: '/goods/add', component: Add },
        { path: '/orders', component: Order },
        { path: '/reports', component: Report }
      ]
    }
  ]
})

router.beforeEach((to, from, net) => {
  if (to.path === '/login') return net()
  const tokenstr = window.sessionStorage.getItem('token')
  if (!tokenstr) return net('/login')
  net()
})
export default router
